//
//  Double+Extension.swift
//  Slaughter
//
//  Created by 邱仙凯 on 2020/10/29.
//  Copyright © 2020 zwb. All rights reserved.
//

import UIKit

extension Double {
    ///四舍五入到j第几位
    public func roundTo(_ places: Int) -> Double {
        let divisor = pow(10.0, Double(places))
        return (self * divisor).rounded() / divisor
    }
   
        /// 小数点后如果只是0，显示整数，如果不是，显示原来的值
        var cleanZero : String {
     
            return self.truncatingRemainder(dividingBy: 1) == 0 ? String(format: "%.0f", self) : String(self)
     
        }
      
    var twoZero : String {
         return String(format: "%.2f", self)
     }
    var threeZero : String {
         return String(format: "%.3f", self)
     }
}
extension Double {
    func numberRMM() -> String {
        return String(self).numberRMM()
    }
}


extension Double {
    func reserved2() -> Double {
        return  Double(String(format:"%.2f",self))!
    }
}
